﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Collections.Generic;
using FinPlusBaseCore;
using FinPlusInterfaces;
using FinPlusCompCore;
using QLNet;

namespace FinPlusCompQuant
{
    public class Cache : FinPlusComponent
    {
        public string Name;
        Dictionary<string, Trade> _trades;
        Dictionary<string, string> _engineMaps;

        //construct
        public Cache(string name)
        {
            Name = name;
            _trades = new Dictionary<string, Trade>();
            _engineMaps = new Dictionary<string, string>();
        }

        //public
        public void Add(string id, Trade trade, string engine)
        {
            _trades[id] = trade;
            _engineMaps[id] = engine;
        }

        public Trade Get(string id)
        {
            if( _trades.ContainsKey(id))
                return _trades[id];

            throw new AnalyticsException(string.Format("trade id {0} not in cache {1}", Name, id));
        }

        public string EngineMap(string id)
        {
            if(_engineMaps.ContainsKey(id))
                return _engineMaps[id];

            throw new TradeCacheException(string.Format("engin map missing {0}", id));
        }
    }
}
